<?php
include(APP_PATH.'/Lib/Action/GlobalAction.class.php');

class AccountAction extends GlobalAction {
    public function index(){
        
        $this->setLang();
        
		$this->display();
    }
    
    public function reg() {
            $this->assign('currentPage', 'reg');
            $this->display();
    }
    
    public function do_reg() {
        if($this->isPost()) {
            
            $tblMember = M('member');
            $tblMember->create();
            $uid = $tblMember->add();

            if ($uid) {
                
                $t = time() + $uid ;
                $r = rand(0, 25);
                
                $passwd = strtoupper(substr(md5(time($t)), $r, 6));
                
                $tblAccount = M('account');
                $tblAccount->create();
                $tblAccount->uid = $uid;
                $tblAccount->password = $passwd;
                $tblAccount->regtime = time();
                $ret = $tblAccount->add();
                
                if ($ret) {
                    $this->assign('uid', $uid);
                    $this->assign('passwd', $passwd);
                    $this->assign('stat', true);
                } else {
                    $this->assign('stat', false);
                    $tblMember->where("uid={$uid}")->delete();
                }
            } else {
                $this->assign('stat', false);    
            }
            
            $this->display();

        }
    }

    public function login() {
        
    }

}